//
//  MXCollocaHeaderView.m
//  MXの衣柜
//
//  Created by 马霄 on 15/8/12.
//  Copyright (c) 2015年 霄 马. All rights reserved.
//

#import "MXCollocaHeaderView.h"
#import "UIImageView+WebCache.h"
@interface MXCollocaHeaderView ()
@property (nonatomic, retain) UIImageView *mainImageView;

@property (nonatomic, retain) UILabel *styleLabel;

@property (nonatomic, retain) UILabel *styleBackGround;
@end


@implementation MXCollocaHeaderView
- (void)dealloc
{
    [_styleBackGround release];
    
    [_careChosenModelS release];
    
    [_mainImageView release];
    
    [_styleLabel release];
    
    [super dealloc];
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.mainImageView = [[[UIImageView alloc] init] autorelease];
        self.mainImageView.backgroundColor = [UIColor redColor];
        [self addSubview:self.mainImageView];
        
        self.styleBackGround = [[[UILabel alloc] init] autorelease];
        self.styleBackGround.backgroundColor = [UIColor grayColor];
        self.styleBackGround.alpha = 0.5;
        self.styleBackGround.text = @"";
        [self.mainImageView addSubview:self.styleBackGround];
        
        self.styleLabel = [[[UILabel alloc] init] autorelease];
        [self.styleLabel setTextColor:[UIColor whiteColor]];
        self.styleLabel.textAlignment = NSTextAlignmentCenter;
        [self.mainImageView addSubview:self.styleLabel];
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
//    CGFloat margin = 10;
    CGFloat wid = self.frame.size.width;
    
    CGFloat mainImageViewX = WIDTHPRO * 10;
    CGFloat mainImageViewY = HEIGHTPRO * 10;
    CGFloat mainImageViewW = wid - 2 * mainImageViewX;
    CGFloat mainImageViewH = mainImageViewW * 1.5;
    self.mainImageView.frame = CGRectMake(mainImageViewX, mainImageViewY, mainImageViewW, mainImageViewH);
    
    CGFloat styleBackGroundX = 0;
    CGFloat styleBackGroundY = mainImageViewH - HEIGHTPRO * 40;
    CGFloat styleBackGroundW = mainImageViewW;
    CGFloat styleBackGroundH = HEIGHTPRO * 40;
    self.styleBackGround.frame = CGRectMake(styleBackGroundX, styleBackGroundY, styleBackGroundW, styleBackGroundH);
    
    CGFloat styleLabelX = 0;
    CGFloat styleLabelY = styleBackGroundY;
    CGFloat styleLabelW = mainImageViewW;
    CGFloat styleLabelH = HEIGHTPRO * 40;
    self.styleLabel.frame = CGRectMake(styleLabelX, styleLabelY, styleLabelW, styleLabelH);
}

-(void)GetCareChosenInfo:(MXCollocaCarefulChosenModel *)carefulchosen
{
    if (_careChosenModelS != carefulchosen) {
        [_careChosenModelS release];
        _careChosenModelS = [carefulchosen retain];
    }
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:carefulchosen.big_image] placeholderImage:[UIImage imageNamed:@"plaseholder"]];
    
    self.styleLabel.text = carefulchosen.info;
}



@end
